package com.thot.timyag.core.support;

import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Set;

import org.springframework.core.io.Resource;
import org.springframework.core.io.UrlResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.lang.Nullable;

/**
 * @author yangjf
 * @time 2019-05-05 15:42
 */
public class SelfPathMatchingResolver extends PathMatchingResourcePatternResolver {

    public SelfPathMatchingResolver(ClassLoader cl) {
        super(cl);
    }

    @Override
    protected void addAllClassLoaderJarRoots(@Nullable ClassLoader classLoader, Set<Resource> result) {
        if (classLoader instanceof URLClassLoader) {
            try {
                URL[] var3 = ((URLClassLoader) classLoader).getURLs();
                int var4 = var3.length;

                for (int var5 = 0; var5 < var4; ++var5) {
                    URL url = var3[var5];

                    try {
                        UrlResource jarResource = "jar".equals(url.getProtocol()) ? new UrlResource(url) : new UrlResource("jar:" + url + "!/");
                        if (jarResource.exists()) {
                            result.add(jarResource);
                        }
                    } catch (MalformedURLException var9) {

                    }
                }
            } catch (Exception var10) {

            }
        }
    }
}
